import Vue from 'vue'
import Router from 'vue-router'
import store from './store'

Vue.use(Router)

const route = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/',
            name: 'index',
            component: () => import('./views/index.vue')
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('./views/login.vue')
        }
    ]
})

route.beforeEach((to, from, next) => {
    if (to.name !== 'login' && !store.getters['Auth/token']) {
        next('/login')
    } else {
        next()
    }
})

export default route
